package com.hbyj.struts.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.poi.hssf.record.formula.functions.Db;
import org.apache.struts2.ServletActionContext;

import com.hbyj.db.function.DbTools;
import com.hbyj.util.Constants;
import com.hbyj.util.PageClass;
import com.opensymphony.xwork2.ActionSupport;

public class DdsbAction extends ActionSupport{
	private String jsonResult;
	private int total;
	private List rows = new ArrayList();
	
	public String getJsonResult() {
		return jsonResult;
	}

	public void setJsonResult(String jsonResult) {
		this.jsonResult = jsonResult;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public List getRows() {
		return rows;
	}

	public void setRows(List rows) {
		this.rows = rows;
	}
	
	public String queryDDSB(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String pageNo = request.getParameter("page");
		int pageSize = Constants.PAGE_KEY;
		String zhCode = request.getParameter("zhCode");
		String startTime = request.getParameter("startTime");
		String endTime = request.getParameter("endTime");
		String type = request.getParameter("qType");//查询类型 yapp表示在预案匹配模块中查询
		String conStr = "";

		String cons_h = "";
		String cons_s = "";

		String conStrForSql = "";

		if(!"".equals(startTime)){
			conStr += " and yjcz12010 >='"+startTime+"' ";
			conStrForSql = "and YJCZ12010 >='"+startTime+"'";
		}
		if(!"".equals(endTime)){
			conStr += " and yjcz12010 <='"+endTime+"'";
			conStrForSql += "and YJCZ12010 <='"+endTime+"'";
		}

		if(type!=null&&type.equals("yapp")){
			cons_h = "and yjcz12000 not in (select fzya03000 from FzyaFzya03) ";
			cons_s = "and yjcz12000 not in (select fzya03000 from fzya_fzya03)";
		}
		String hql = "from YjczYjcz12 where yjcz12000 like '"+zhCode+"' "+cons_h + conStr+"order by yjcz12010";
		String countHql = "select count(*) from YJCZ_YJCZ12 where YJCZ12000 like '"+zhCode+"' "+cons_s +conStrForSql;

		int t = DbTools.getDataSQLCount(countHql);
		PageClass page = new PageClass();
		page.setPageShow(pageSize);  //设置每页显示的行数
		page.setPageCount(t);  //设置总页数
		page.setCurrentPage(Integer.parseInt(pageNo));  //设置当前页
		int first=page.getNextIndex(); //获得开始的索引值
		int max=page.getPageShow();  //获得每次显示的值
		rows = (List)DbTools.findPageHQL(first, max,hql);
		total = t;
		return SUCCESS;
	}
}
